{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from xgboost import XGBRFRegressor as XGBR\n",
    "from numpy import *\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.linear_model import LinearRegression as LinearRegression\n",
    "from sklearn.model_selection import KFold,cross_val_score as CVS,train_test_split as TTS\n",
    "from sklearn.metrics import mean_squared_error as MSE\n",
    "wine = pd.read_excel(\"RF_lgb_Relation.xlsx\",header=0)\n",
    "wine0 = pd.read_csv(\"after_process_database.csv\",header=0)\n",
    "feature20 = pd.read_csv(\"final_features.csv\",header=0)\n",
    "feature_20=feature20.loc[:,'name'].values\n",
    "after_feature=wine.loc[:49,'Rela删除后的RF'].values\n",
    "index50 = wine0.loc[:,after_feature].values\n",
    "index20 = wine0.loc[:,feature_20].values\n",
    "yList = wine0.pIC50.values\n",
    "index20"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([[28.27793195,  0.46912557, -0.12645316, ...,  1.35723722,\n",
       "         0.73317565, -1.3313031 ],\n",
       "       [31.07674804,  0.44912557, -0.12645324, ...,  1.36403994,\n",
       "         0.73317565, -1.3786282 ],\n",
       "       [30.90106359,  0.48071295, -0.14312582, ...,  1.20091777,\n",
       "         0.83955604, -1.60835379],\n",
       "       ...,\n",
       "       [44.46643496,  0.50975105,  0.05139418, ...,  0.83563916,\n",
       "         0.95805898, -5.99302785],\n",
       "       [32.17931565,  0.52926898,  0.06039729, ...,  0.87127637,\n",
       "         0.93249605, -5.77914217],\n",
       "       [44.46643496,  0.5052159 ,  0.0600449 , ...,  0.89578922,\n",
       "         0.95805898, -5.97813907]])"
      ]
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "reg1= XGBR(n_estimator = 120)\n",
    "MAE=CVS(reg1,index50,yList,cv=5,scoring='neg_mean_absolute_error')#只在训练集上，更严谨"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[23:01:47] WARNING: ../src/learner.cc:573: \n",
      "Parameters: { \"n_estimator\" } might not be used.\n",
      "\n",
      "  This may not be accurate due to some parameters are only used in language bindings but\n",
      "  passed down to XGBoost core.  Or some parameters are not used but slip through this\n",
      "  verification. Please open an issue if you find above cases.\n",
      "\n",
      "\n",
      "[23:08:30] WARNING: ../src/learner.cc:573: \n",
      "Parameters: { \"n_estimator\" } might not be used.\n",
      "\n",
      "  This may not be accurate due to some parameters are only used in language bindings but\n",
      "  passed down to XGBoost core.  Or some parameters are not used but slip through this\n",
      "  verification. Please open an issue if you find above cases.\n",
      "\n",
      "\n",
      "[23:15:46] WARNING: ../src/learner.cc:573: \n",
      "Parameters: { \"n_estimator\" } might not be used.\n",
      "\n",
      "  This may not be accurate due to some parameters are only used in language bindings but\n",
      "  passed down to XGBoost core.  Or some parameters are not used but slip through this\n",
      "  verification. Please open an issue if you find above cases.\n",
      "\n",
      "\n",
      "[23:23:03] WARNING: ../src/learner.cc:573: \n",
      "Parameters: { \"n_estimator\" } might not be used.\n",
      "\n",
      "  This may not be accurate due to some parameters are only used in language bindings but\n",
      "  passed down to XGBoost core.  Or some parameters are not used but slip through this\n",
      "  verification. Please open an issue if you find above cases.\n",
      "\n",
      "\n",
      "[23:28:11] WARNING: ../src/learner.cc:573: \n",
      "Parameters: { \"n_estimator\" } might not be used.\n",
      "\n",
      "  This may not be accurate due to some parameters are only used in language bindings but\n",
      "  passed down to XGBoost core.  Or some parameters are not used but slip through this\n",
      "  verification. Please open an issue if you find above cases.\n",
      "\n",
      "\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "MAE.mean()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "-0.8055031544577173"
      ]
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.7.10",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.10 64-bit ('deeplearning': conda)"
  },
  "interpreter": {
   "hash": "a2441be928683876ab9582b799059e1f9f764e7f9dd2044f4d30ad5ffc1df7fc"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}